package com.mini.framework.web;

import java.lang.reflect.Method;

public class RequestHandler {
	
	private Method method;
	
	private Object obj;
	
	private ViewHandler viewHandler;
	
	private String[] paramClassNames;
	
	public RequestHandler(Method method,Object obj,ViewHandler handler){
		this.method = method;
		this.obj = obj;
		this.viewHandler = handler;
		
		Class<?>[] paraTypes = method.getParameterTypes();
		paramClassNames = new String[paraTypes.length];
		for(int i=0;i<paraTypes.length;i++){
			paramClassNames[i] = paraTypes[i].getName();
		}
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public ViewHandler getViewHandler() {
		return viewHandler;
	}

	public void setViewHandler(ViewHandler viewHandler) {
		this.viewHandler = viewHandler;
	}
	
	
	public String[] getParamClassNames() {
		return paramClassNames;
	}

	public void setParamClassNames(String[] paramClassNames) {
		this.paramClassNames = paramClassNames;
	}

	public Object invoke(Object[] params){
		Object ret = null;
		try{
			ret = method.invoke(obj, params);
		}catch(Exception e){
			e.printStackTrace();
		}
		return ret;
	}
	

}
